package area.vo;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Reflact {
	static Area a = new Area(1,"name",2,1,2);
	public static void main(String[] args)throws Exception {
		Class c = Class.forName("area.vo.Area");
		c = Area.class;
		c = a.getClass();
		
		//System.out.println("========类信息==========");
		//System.out.println("类名:"+c.getName());
		//System.out.println("权限修饰符："+c.getModifiers()+";包名："+c.getPackage()+";简单类名："+c.getSimpleName());
		
		//System.out.println("==========获取属性信息==============");
		Field [] fs = c.getDeclaredFields();
		fieldInfo(fs);
		Field areaid = c.getDeclaredField("areaid");
		areaid.set(a, "idid");
		Field status = c.getDeclaredField("status");
		status.set(a, 3);
		fieldInfo(fs);
		
		//System.out.println("=========获取方法信息=========");
		Method getAreaid = c.getMethod("getAreaid", null);
		Object getReu = getAreaid.invoke(a, null);
		//System.out.println("getAreaid()="+getReu.toString());
		Method setAreaid = c.getDeclaredMethod("setAreaid", String.class);
		Object setReu = setAreaid.invoke(a,"setvalue");
		//System.out.println("set方法返回结果"+setReu);
		
		Constructor con = c.getConstructor(String.class,String.class,String.class,int.class,Integer.class);
		Object acon = con.newInstance("c1","c2","c3",4,5);
		//System.out.println(acon.toString());
	}
	
	public static void fieldInfo(Field [] fs) throws Exception{
		for(Field f : fs){
			int modify = f.getModifiers();//权限修饰符
			String type = f.getType().getName();//数据类型
			String proName = f.getName();//属性名
			String value = f.get(a).toString();//属性值
			//System.out.println("权限修饰符："+modify+";数据类型："+type+";属性名："+proName+"="+value);
		}
	};
}
